<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AdminAuthController extends Controller
{
    public function login(Request $request)
    {
        $credentials = $request->only('account', 'password');

        if (!$token = auth('admin')->attempt($credentials)) {
            return response()->json(['error' => '账号或密码错误'], 401);
        }

        return response()->json([
            'admin' => auth('admin')->user(),
            'access_token' => $token,
            'token_type' => 'bearer'
        ]);
    }
}
